<template>
    <div class="project-container" ref="projectContainer" v-load="isLoadingRef" @scroll="handleScroll">
        <div v-for="item in storeDataRef" :key="item.id" class="project-item">
            <a
                :href="
                    item.url
                        ? item.url
                        : `javascript:alert('该项目无法通过外网访问')`
                "
                :target="item.url ? '_blank' : '_self'"
            >
                <img class="thumb" v-load-image-lazy="item.thumb" />
            </a>
            <div class="info">
                <h2>
                    <a
                        :href="
                            item.url
                                ? item.url
                                : `javascript:alert('该项目无法通过外网访问')`
                        "
                        :target="item.url ? '_blank' : '_self'"
                    >
                        {{ item.name }}
                    </a>
                </h2>
                <a
                    class="github"
                    target="_blank"
                    :href="item.github"
                    v-if="item.github"
                >
                    github
                </a>
                <p v-for="(desc, i) in item.description" :key="i">
                    {{ desc }}
                </p>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { storeToRefs } from "pinia";
import { ref } from "vue";
import { $bus, bindMainScrollEvent,bindSetScrollEvent } from "~@/bus/busIndex";
import { useProjectStore } from "~@/store/modules/project";
import { vLoad } from "~@/directives/loading/loadingDirective";
import { vLoadImageLazy } from "~@/directives/imagelazy/imageLazy";
const projectStore=useProjectStore();
const {isLoadingRef,storeDataRef}=storeToRefs(projectStore);
const projectContainer=ref<HTMLDivElement>();

projectStore.actionGetProject();

// bindMainScrollEvent(projectContainer.value);
bindSetScrollEvent((scrollTop)=>{
    projectContainer.value!.scrollTop=scrollTop;
});

const handleScroll=()=>{
    $bus.emit('mainScroll',projectContainer.value);
}
////#region defineXxx
//defineOptions({
//name:
//});

//const props=defineProps({
//propA:{
//type:String,
//required:true
//},
//propB:{
//type:Number,
//default:1
//},
//propC:{
//type:String as PropType<MyType>,
//required:true
//},
//});

//const emit = defineEmits<{
//event1:[para1:number,para2:string],
//event2:[para1:number,para2:string],
//}>();
////#endregion
</script>
<style lang="less" scoped>
.project-container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 20px;
  position: relative;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.project-item {
  transition: 0.5s;
  padding: 20px;
  display: flex;
  margin-bottom: 20px;
  &:hover {
    box-shadow: -1px 1px 5px #000;
    transform: scale(1.01) translate(3px, -3px);
    color: inherit;
  }
  .thumb {
    width: 250px;
    min-height: 150px;
    flex: 0 0 auto;
    object-fit: cover;
    border-radius: 5px;
    margin-right: 15px;
  }
  .info {
    line-height: 1.7;
    flex: 1 1 auto;
    h2 {
      margin: 0;
    }
  }
  .github {
    font-size: 14px;
    color: @primary;
  }
}</style>
